import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome()
url = ("file:///C:/Users/Mr%20MING/PycharmProjects/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/learn-git/select%E6%93%8D%E4%BD%9C/select%E6%93%8D%E4%BD%9C%E5%AE%9E%E4%BE%8B.html")
# url = "https://www.baidu.com"
driver.get(url)

# 找到并点击小刚
driver.find_element(By.XPATH, '//option[text()="小刚"]').click()
time.sleep(2)

# 另一种方式
#先找到Select元素，再把元素对象传入select
s = driver.find_element(By.ID, "myselect")
s_obj = Select(s)
s_obj.select_by_visible_text("小刚")
s_obj.select_by_index("小明")
# option value属性选择
s_obj.select_by_value("小")
# 通过索引
s_obj.select_by_index(2)

time.sleep(2)
